package com.iyundao.io.controller;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.iyundao.io.Service.WishService;
import com.iyundao.io.model.Wish;
import com.iyundao.io.tools.IntegralOperationVo;
import com.iyundao.io.tools.ResponseData;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping(value = "/wish")
public class WishController {

    @Autowired
    private WishService wishService;

    @ApiOperation(value="心愿单添加", notes="心愿单添加")
    @RequestMapping(value = "/addwish", produces = {"application/json;charset=UTF-8"})
    @CrossOrigin
    public ResponseData addWish(@RequestBody JSONObject params) {
        Wish wish = JSON.toJavaObject(params, Wish.class);
        return wishService.insert(wish);

    }

    @ApiOperation(value="心愿单删除", notes="心愿单删除")
    @RequestMapping(value = "/delwish", produces = {"application/json;charset=UTF-8"})
    @CrossOrigin
    public ResponseData delWish(@RequestBody JSONObject params) {
        Wish wish = JSON.toJavaObject(params, Wish.class);
        return wishService.del(wish);

    }

    @ApiOperation(value="心愿单提交", notes="心愿单提交")
    @RequestMapping(value = "/wishsubmit", produces = {"application/json;charset=UTF-8"})
    @CrossOrigin
    public ResponseData wishSubmit(@RequestBody JSONObject params) {
        String s = String.valueOf(params);
        List<Wish> list = JSON.parseArray(s, Wish.class);

        return wishService.addWishSubmit(list);

    }

    @ApiOperation(value="确认兑换", notes="确认兑换")
    @RequestMapping(value = "/exchange", produces = {"application/json;charset=UTF-8"})
    @CrossOrigin
    public ResponseData exchange(@RequestBody JSONObject params) {
        IntegralOperationVo integralOperationVo = JSON.toJavaObject(params, IntegralOperationVo.class);

        return wishService.exchange(integralOperationVo);

    }

}
